package com.xingda.packing.dmds.task.handle;

import com.xingda.packing.dmds.domain.PackProductionLine;
import com.xingda.packing.dmds.enums.TaskState;
import com.xingda.packing.dmds.enums.TaskType;
import com.xingda.packing.dmds.enums.WheelType;
import com.xingda.packing.dmds.task.ticket.StorageTicket;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component("storageHandleDMDS")
@Slf4j
public class StorageHandle implements TaskHandleService {
    @Override
    public boolean accept(PackProductionLine productionLine, int area) {
        return checkTask(productionLine.getRobot().getTaskTicket(area), TaskType.STORAGE);
    }

    @Override
    public void process(PackProductionLine productionLine, int area) {
        StorageTicket ticket = (StorageTicket) productionLine.getRobot().getTaskTicket(area);
        if (productionLine.getRobot().canAssignTask(area)) {
            log.info("开始执行抓取位到缓存位-handle-区域{}", area);
            productionLine.getRobot().startStorage(WheelType.getByTypeName(ticket.getWheel().getVFree2()).getType(), ticket.getCacheLocationNo(), area);
            ticket.setState(TaskState.RUNING);
            //事件记录
            productionLine.getRobot().handleStorageEvent(ticket, area);
            log.info("执行完成抓取位到缓存位-handle-区域{}", area);
        }
    }
}
